module.exports = {
	/**
	 * 数据删除
	 * @url agent/toufang/kh/delete 前端调用的url参数地址
	 * data 请求参数 说明
	 * res 返回参数说明
	 * @params {Number} code 错误码，0表示成功
	 * @params {String} msg 详细信息
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid
		} = data;
		let res = {
			code: 0,
			msg: 'ok'
		};
		try {
			console.log("data=", data._id);
			//通过data._id获取旧数据
			let old_datas = await db.collection('a_dy_tfurl').doc(data._id).get()
			//记录操作日志到数据库
			let addlogs = await vk.baseDao.add({
				dbName: "opendb-admin-log",
				dataJson: {
					type: "delete",
					path:"admin/dls/kh/dytflj/delete",
					edit_log: "删除数据 ",
					obj_id: old_datas.data[0]._id,
					old_data: old_datas.data[0],
					new_data: "",
					user_id: userInfo._id,
					user_name: userInfo.username,
					nick_name: userInfo.nickname,
					ip: originalParam.context.CLIENTIP,
					ua: originalParam.context.CLIENTUA
				}
			});
			
		} catch (err) {
			console.log("日志加入失败");
		}
		// 业务逻辑开始-----------------------------------------------------------
		// 获取前端传过来的参数
		let {
			_id
		} = data;
		// 参数验证开始
		if (vk.pubfn.isNull(_id)) return {
			code: -1,
			msg: 'id不能为空'
		};
		// 参数验证结束
		let dbName = "a_dy_tfurl"; // 表名
		// 执行数据库 deleteById 命令
		await vk.baseDao.deleteById({
			dbName,
			id: _id
		});
		await vk.baseDao.del({
			dbName: 'a_agent_settingTV',
			whereJson: {
				tfid: _id
			}
		});
		await vk.baseDao.del({
			dbName: 'a_config',
			whereJson: {
				name: "RebackPercent",
				tfid: _id
			}
		});

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}

}